package com.benjaminwan.read.free.utils

import android.content.Context
import androidx.annotation.ArrayRes
import androidx.annotation.StringRes
import com.benjaminwan.read.free.app.App

/**
 * 获取StringArray
 * @param id
 * @return Array<String>
 **/
fun getStringArray(@ArrayRes id: Int): Array<String> =
    App.INSTANCE.resources.getStringArray(id)

fun getIntArray(@ArrayRes id: Int): IntArray =
    App.INSTANCE.resources.getIntArray(id)

fun getString(@StringRes id: Int): String =
    App.INSTANCE.getString(id)

fun Context.getStringByIdentifier(idStr: String): String {
    val strId = resources.getIdentifier(idStr, "string", packageName)
    if (strId == 0) return ""
    return getString(strId)
}

fun getStringByIdentifier(idStr: String): String {
    return App.INSTANCE.getStringByIdentifier(idStr)
}

fun Context.getStringArrayByIdentifier(idStr: String): Array<String> {
    val strId = resources.getIdentifier(idStr, "array", packageName)
    if (strId == 0) return emptyArray()
    return resources.getStringArray(strId)
}

fun getStringArrayByIdentifier(idStr: String): Array<String> {
    return App.INSTANCE.getStringArrayByIdentifier(idStr)
}